{include file="admin@public/header"/}
<link rel="stylesheet" href="/public/static/admin/css/report.css" />
<link rel="stylesheet" type="text/css" href="/public/static/admin/easyui/jeasyui/themes/icon.css">
<style>
	.ui-icon-ellipsis {
		right: 5px;
	}

	#filter-menu .con {
		width: 355px;
	}

	#filter-menu label.tit {
		width: 80px;
	}

	/*.ui-jqgrid tr.jqgrow td {
	white-space: normal !important;
	}
	*/
	.no-query {
		background: url("/public/static/admin/css/img/no_query.png") no-repeat scroll 100px 60px #fff;
		background-position: center;
		border: 1px solid #ddd;
		border-top: none;
		height: 402px;
		margin-right: 0;
	}

	.box-flex {
		overflow: hidden;
		zoom: 1;
	}

	.box-flex .flex {
		float: left;
		width: 33.3%;
	}

	.grid-title {
		font-size: 24px;
		text-align: center;
		clear: none;
	}

	.ui-print .grid-wrap {
		padding: 10px 0 0 30px;
	}

	#conditions-trigger {
		background: url(/public/static/admin/css/img/bg.png) no-repeat;
		border: 0px;
		width: 74px;
		box-shadow: 0px 0px;
	}

	#filter-menu .conditions-trigger>b {
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -8px;
		width: 16px;
		height: 16px;
		background: url(/public/static/admin/css/img/down.png) 2px 5px no-repeat;
	}

	#filter-menu .conditions-trigger>b.act {
		background: url(/public/static/admin/css/img/up.png) 2px 5px no-repeat;
	}

	#filter-menu .btns {
		position: absolute;
		top: 7px;
		right: 0px;
	}

	.layui-form-checkbox[lay-skin=primary] i {
		padding: 0;
	}

	.layui-form-checked[lay-skin=primary] i {
		border-color: #5dc5e7;
		background-color: #5dc5e7;
		color: #fff;
		padding: 0;
	}

	.layui-form-checkbox[lay-skin=primary]:hover i {
		border-color: #5dc5e7;
	}

	.ui-droplist-wrap {
		height: auto;
	}

	#filterItems {
		height: auto;
	}
</style>

<div class="wrapper">
	<!-- header -->
	<div class="mod-search cf">
		<div class="l layui-form" id="filter-menu">
			<ul class="ul-inline fix" id="filterItems">
				<li id="date" style="display: list-item;"><label>单据日期:</label>
					<input type="date" id="startdate" class="ui-input " value="" style="width: 115px;">
					<span class="todate"> 至 </span>
					<input type="date" id="enddate" class="ui-input " value="" style="width: 115px;">
				</li>

				<!-- 选择供应商类别 -->
				{include file="admin@select/supplier_category"/}

				<!-- 选择供应商 -->
				{include file="admin@select/supplier"/}

				<li id="billNum" style="display: list-item;">
					<label>采购单号</label>
					<input type="text" value="" style="width:115px;" class="ui-input ui-input-ph" name="sn" id="sn"
						placeholder="请输入单号查询">
				</li>
				<li class="chk-list" id="chk-blank" style="display: list-item;height: 44px;">
					<span class="chk" style="height: 44px;padding-top: 7px;box-sizing: border-box;">
						<input type="checkbox" name="showBlank" id="payment_rate" lay-skin="primary" title="付款率100%不显示"
							value="0">
					</span>
					<div class="btns" style="top: -4px;"><a class="ui-btn mrb ui-btn-search" id="filter-submit">查询</a>
					</div>
				</li>
			</ul>
			<!-- <a href="#" id="conditions-trigger" class="ui-btn conditions-trigger" tabindex="-1">&nbsp;更多条件<b></b></a> -->
		</div>
	</div>

	<!-- 下拉树选择（供应商类别） -->
	{include file="admin@popup/supplier_category"/}

	<!-- no data -->
	<div class="no-query"></div>
	<!-- grid begin -->
	<div class="ui-print" id="ui-print" style="visibility: hidden;">
		<!-- 列配置 -->
		<div class="cf box-flex">
			<div class="flex">
				<span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>

			<div class="grid-title flex">采购付款一览表</div>
			<div class="fr">
				<a href="#" class="ui-btn ui-btn-export btn-sm mrb fl" id="btn-export">导出</a>
				<a href="javascript:void(0)" class="ui-btn ui-btn-print btn-sm fl" id="btn-print"
					onclick="preview(1)">打印</a>
			</div>
		</div>

		<div class="grid-wrap" id="grid-wrap" style="padding-bottom: 30px;padding-right: 30px;">
			<!--startprint-->
			<!-- <div class="grid-title">采购付款一览表</div> -->
			<div class="grid-subtitle"></div>
			<table id="grid"></table>
			<!--endprint-->
			<div id="page"></div>
		</div>
	</div>
	<!-- grid end -->

	<!--  以隐藏的方式获取商品的样式 ，作用是赋值 -->
	<div style="display:none;">
		<input type="text" id="supplierid" value="" autocomplete="off" readonly="">
		<input type="text" id="goodsid" value="" autocomplete="off" readonly="">
		<input type="text" id="storeid" value="" autocomplete="off" readonly="">
	</div>
</div>

<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>

<script>
	$(document).ready(function () {
		// 获取当前日期
		var myDate = new Date;
		var year = myDate.getFullYear(); //获取当前年
		var mon = myDate.getMonth() + 1; //获取当前月
		var date = myDate.getDate(); //获取当前日
		// console.log(year + '-' + mon + '-' + date)
		if (mon < 10) {
			mon = "0" + mon;
		}
		if (date < 10) {
			date = "0" + date;
		}
		$("#startdate").val(year + '-' + mon + '-01');
		$("#enddate").val(year + '-' + mon + '-' + date);
	});
</script>
<script type="text/javascript">
	//$(function(){
	$(document).ready(function () {

		// 点击查询按钮
		$("#filter-submit").click(function () {
			$("#ui-print").css({ "visibility": "visible" });  //显示表格数据
			$(".no-query").hide();  //隐藏提示

			// 设置表格高度
			$("#grid").setGridHeight($(window).height() - 230 - $("#filter-menu").height() + "px");

			var startdate = $('#startdate').val();
			var enddate = $('#enddate').val();
			var supplierid = $('#supplier_id').val();
			var sn = $('#sn').val();
			var supplier_category_id = $('#supplier_category_id').val();
			var payment_rate = 0;
			if ($("#payment_rate").get(0).checked) {
				payment_rate = 1;
			} else {
				payment_rate = 0;
			}

			$("div.grid-subtitle").text("日期: " + startdate + " 至 " + enddate);

			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: {
					'ajax': '100',
					'startdate': startdate,
					'enddate': enddate,
					'supplierid': supplierid,
					supplier_category_id: supplier_category_id,
					sn: sn,
					payment_rate: payment_rate
				}, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
		});

		//alert("1111");
		$("#grid").jqGrid({
			url: '/scm/invpupay/index.html',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			width: '100%',
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: ["id", "供应商类别", "供应商", "业务类别", "单据日期", "单据编号", "采购金额", "优惠金额", "优惠后金额", "本次付款", "应付款余额", "付款率", "备注", "pid"],
			colModel: [
				{ name: 'id', index: 'id', width: 80, label: "id", hidden: true },
				{ name: 'supplier_category', index: '', width: 150, label: "供应商类别", align: "center" },
				{ name: 'supplier_name', index: '', width: 150, label: "供应商", align: "center" },
				{ name: 'type_name', index: '', width: 110, label: "业务类别", align: "center" },
				{ name: 'addtime', index: '', width: 110, label: "单据日期", align: "center" },
				{ name: 'sn', index: '', width: 120, label: "单据编号", align: "center" },
				{ name: 'purchase_cost', index: '', width: 100, label: "采购金额", align: "center" },
				{ name: 'yh_e', index: '', width: 100, label: "优惠金额", align: "center" },
				{ name: 'yh_price', index: '', width: 100, label: "优惠后金额", align: "center" },
				{ name: 'payment', index: '', width: 100, label: "本次付款", align: "center" },
				{ name: '', index: '', width: 100, label: "应付款余额", align: "center" },
				{ name: 'payment_rate', index: '', width: 100, label: "付款率", align: "center" },
				{ name: 'mark', index: '', width: 200, label: "备注" },
				{ name: 'pid', hidden: true },
			],
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置

			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			},

			//双击表格行事件
			ondblClickRow: function (row) {
				var rowData = $('#grid').jqGrid('getRowData', row);
				parent.tab.addTabItem({
					tabid: "purchaseinvPu",
					text: "商品采购明细表",
					url: '/scm/invpu/edit.html?id=' + rowData.id,
				});
			},

			// 合计
			footerrow: true,
			gridComplete: function () {
				var purchase_prices = parseFloat($("#grid").getCol('purchase_price', false, 'sum')).toFixed(2);
				var discount_prices = parseFloat($("#grid").getCol('discount_price', false, 'sum')).toFixed(2);
				var after_discounts = parseFloat($("#grid").getCol('after_discount', false, 'sum')).toFixed(2);

				$("#grid").footerData('set', { "supplier_category": '合计:', purchase_price: purchase_prices, discount_price: discount_prices, after_discount: after_discounts });

				// 合并合计单元格
				var $footRow = $("#grid").closest(".ui-jqgrid-bdiv").next(".ui-jqgrid-sdiv").find(".footrow");
				$footRow.find('>td[aria-describedby="grid_supplier_category"],>td[aria-describedby="grid_supplier_name"],>td[aria-describedby="grid_type_name"],>td[aria-describedby="grid_addtime"]').css("border-right-color", "transparent");

			},
		});


	});

</script>



{include file="admin@public/footer"/}